<!--
 * @Author: lbz_dev 1982212843@qq.com
 * @Date: 2023-11-21 11:11:28
 * @LastEditors: lbz_dev 1982212843@qq.com
 * @LastEditTime: 2023-11-27 09:57:25
 * @FilePath: \fct\src\views\Tools\3dAnalysis\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="extra3dPosition" @click="check3dExtra($event)">
    <div
      v-for="item in toolArr"
      :key="item.id"
      class="extra_item"
      :extraid="item.id"
    >
      {{ item.label }}
    </div>
  </div>
  <shootAreaAnalysis v-if="analysisId == '6'"></shootAreaAnalysis>
</template>

<script setup>
import { ref, watch } from "vue";
import tool3dState from "../../../store/modules/tool3dState";
import shootAreaAnalysis from "./components/shootAreaAnalysis.vue";
import draggable from 'vuedraggable'
const tool3dStateStore = tool3dState();
let toolArr = [
  {
    label: "通视分析",
    id: "1",
  },
  {
    label: "日照分析",
    id: "2",
  },
  {
    label: "限高分析",
    id: "3",
  },
  {
    label: "天际线分析",
    id: "4",
  },
  {
    label: "淹没分析",
    id: "5",
  },
  {
    label: "可视域分析",
    id: "6",
  },
  {
    label: "模型压平",
    id: "7",
  },
];
let analysisId = ref("0");
const check3dExtra = (e) => {
  const id = e.target.getAttribute("extraid");
  tool3dStateStore.updateCurrent3dState(id);
};
watch(
  () => tool3dStateStore.current3dState,
  (id) => {
    analysisId.value = id;
    if (id == "7") {
      smashing();
    }
  }
);
const smashing = () => {
  tileset.readyPromise.then(function () {
    // let boundingbox = new Cesium.AxisAlignedBoundingBox(
    //   new Cesium.Cartesian3(minX, miny, minz),
    //   new Cesium.Cartesian3(maxX, maxy, maxz)
    // );
    var selectedTiles = [];
    tileset.root.children.forEach((tile) => {
      selectedTiles.push(tile);
    });
    for (var i = 0; i < selectedTiles.length; i++) {
      var tile = selectedTiles[i];
      tile.content.readyPromise.then(function () {
        var content = tile.content;
        var positions = content.attributes.position.values;
        var normals = content.attributes.normal.values;
        var indices = content.indices;
        // TODO: 对 positions、normals 和 indices 进行压平
        content.attributes.position.values = positions;
        content.attributes.normal.values = normals;
        content.indices = indices;
        tileset.invalidateTile(tile);
      });
    }
    tileset.loadProgress.addEventListener(function (numberOfPendingRequests) {
      if (numberOfPendingRequests === 0) {
        tileset.makeStyleDirty();
      }
    });
  });
};
</script>

<style scoped lang="less">
.extra_item {
  height: 40px;
  width: 100px;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  margin: 15px;
}
.extra_item:hover {
  background: #3aa6f4;
  color: white;
}
.extra3dPosition {
  position: absolute;
  right: 20px;
  top: 50%;
  background-color: white;
  border-radius: 13px;
  z-index: 9;
  transform: translateY(-50%);
}
</style>
